#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[])
{
	if(argc!=4)
	{
		cout << "Use: batch configuration, output, runner" << endl;
		cout << "Received: " << argc << endl;
		return 1;
	}
	int *Nstart;
	int *Nend;
	int *Ninc;
	int *Do;
	int *De;
	int *Tcrit;
	int total;
	int spread;

	ifstream batch(argv[1]);

	batch >> total;
	batch >> spread;

	Nstart=new int[total];
	Nend=new int[total];
	Ninc=new int[total];
	Do=new int[total];
	De=new int[total];
	Tcrit=new int[total];

	for(int i=0;i<total;i++)
	{
		batch >> Nstart[i];
		//cout << Nstart[i] << ' ';
	}
	//cout << endl;

	for(int i=0;i<total;i++)
	{
		batch >> Nend[i];
		//cout << Nend[i] << ' ';
	}
	//cout << endl;

	for(int i=0;i<total;i++)
	{
		batch >> Ninc[i];
		//cout << Ninc[i] << ' ';
	}
	//cout << endl;

	for(int i=0;i<total;i++)
	{
		batch >> Do[i];
		//cout << Do[i] << ' ';
	}
	//cout << endl;

	for(int i=0;i<total;i++)
	{
		batch >> De[i];
		//cout << De[i] << ' ';
	}
	//cout << endl;

	for(int i=0;i<total;i++)
	{
		batch >> Tcrit[i];
		//cout << Tcrit[i] << ' ';
	}
	//cout << endl;



	ofstream runner(argv[3]);
	char mystring[250];
		
	for(int i=0;i<total;i++)
	{
		sprintf(mystring,"makeBatch.out %d %d %d %d %d %d %d run%d %s",
				Nstart[i],Nend[i],Ninc[i],Do[i],De[i],Tcrit[i]-spread,Tcrit[i]+spread,i,argv[2]);
		
		//cout << mystring << endl;
		system(mystring);
		
		runner << "run" << i << endl;
	}
	runner.close();
	system("chmod +x run*");

	delete [] Nstart;
	delete [] Nend;
	delete [] Ninc;
	delete [] Do;
	delete [] De;
	delete [] Tcrit;

}
